import Cookies from 'js-cookie'
import {
  baseData,
  baseSo
} from '@/api/common'

const loseReason = [{
  value: '0',
  label: '工作经验不满足要求数量'
}, {
  value: '1',
  label: '技术不符合岗位要求'
}, {
  value: '2',
  label: '月薪不匹配'
}, {
  value: '3',
  label: '学历不匹配'
}, {
  value: '4',
  label: '行业不匹配'
}, {
  value: '5',
  label: '招聘类型不匹配'
}]

const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
    withoutAnimation: false
  },
  device: 'desktop',
  size: Cookies.get('size') || 'medium',
  enNature: ['国企', '民营', '合资', '外商独资', '股份制企业', '上市公司', '代表处', '国家机关', '事业单位', '银行', '医院', '学校/下级学院', '律师事务所', '社会团体',
    '港澳台公司', '其他'
  ], // 企业性质
  areaData: [], // 城市数据,
  tradeData: [], // 行业数据,
  positionData: [], // 职位职类
  // 学历数据
  eduLevels: [{
    value: '0',
    label: '初中及以下'
  }, {
    value: '1',
    label: '高中'
  }, {
    value: '2',
    label: '中专/中技'
  }, {
    value: '3',
    label: '大专'
  }, {
    value: '4',
    label: '本科'
  }, {
    value: '5',
    label: '研究生'
  }, {
    value: '6',
    label: 'MBA/EMBA'
  }, {
    value: '7',
    label: '博士'
  }],
  // 招聘类型
  recruitType: [{
    value: '0',
    label: '社会招聘'
  }, {
    value: '1',
    label: '校园招聘'
  }],
  // 职业性质
  jobNature0: [{
    value: '0-0',
    label: '全职'
  }, {
    value: '0-1',
    label: '兼职'
  }],
  // 职业性质
  jobNature1: [{
    value: '1-0',
    label: '应届生'
  }, {
    value: '1-1',
    label: '实习生'
  }],
  // 年龄要求
  age: [{
    value: '0',
    label: '不限'
  }, {
    value: '18',
    label: '18岁以下'
  }, {
    value: '25',
    label: '25岁以下'
  }, {
    value: '30',
    label: '30岁以下'
  }, {
    value: '35',
    label: '35岁以下'
  }, {
    value: '40',
    label: '40岁以下'
  }, {
    value: '45',
    label: '45岁以下'
  }, {
    value: '50',
    label: '50岁以下'
  }, {
    value: '55',
    label: '55岁以下'
  }, {
    value: '60',
    label: '60岁以下'
  }, {
    value: '65',
    label: '65岁以下'
  }],
  // 院校性质
  schoolLevel: [{
    value: '0',
    label: '普通大学'
  }, {
    value: '1',
    label: '211院校'
  }, {
    value: '2',
    label: '985院校'
  }],
  // 职称要求
  jobRequire: [{
    value: '0',
    label: '初级'
  }, {
    value: '1',
    label: '中级'
  }, {
    value: '2',
    label: '副高级'
  }, {
    value: '3',
    label: '高级'
  }],
  // 经验限制
  experience: [{
    value: '0,999',
    label: '不限'
  }, {
    value: '0,0',
    label: '无经验'
  }, {
    value: '0,1',
    label: '1年以下'
  }, {
    value: '1,3',
    label: '1-3年'
  }, {
    value: '3,5',
    label: '3-5年'
  }, {
    value: '5,10',
    label: '5-10年'
  }, {
    value: '10,99',
    label: '10年以上'
  }],
  // 性别
  sex: [{
    value: '1',
    label: '男'
  }, {
    value: '2',
    label: '女'
  }],
  // 语言
  language: [
    { label: '英语', value: '英语' },
    { label: '汉语', value: '汉语' },
    { label: '日语', value: '日语' },
    { label: '法语', value: '法语' },
    { label: '德语', value: '德语' },
    { label: '俄语', value: '俄语' },
    { label: '韩语/朝鲜语', value: '韩语/朝鲜语' },
    { label: '西班牙语', value: '西班牙语' },
    { label: '葡萄牙语', value: '葡萄牙语' },
    { label: '阿拉伯语', value: '阿拉伯语' },
    { label: '意大利语', value: '意大利语' },
    { label: '瑞典语', value: '瑞典语' },
    { label: '泰国语', value: '泰国语' },
    { label: '波兰语', value: '波兰语' },
    { label: '荷兰语', value: '荷兰语' },
    { label: '捷克语', value: '捷克语' },
    { label: '拉丁语', value: '拉丁语' },
    { label: '挪威语', value: '挪威语' },
    { label: '世界语', value: '世界语' }],
  // 简历状态
  resumeState: [{
    value: '0',
    label: '新简历'
  }, {
    value: '1',
    label: '初筛'
  }, {
    value: '2',
    label: '面试'
  }, {
    value: '3',
    label: '录用'
  }, {
    value: '4',
    label: '入职'
  }, {
    value: '5',
    label: '过滤'
  }],
  // 简历状态
  jobState: [{
    value: '1',
    label: '已阅读'
  }, {
    value: '2',
    label: '不合适'
  }, {
    value: '3',
    label: '通过筛选'
  }, {
    value: '4',
    label: '面试'
  }, {
    value: '5',
    label: '已发offer(已录用)'
  }, {
    value: '6',
    label: '已入职'
  }, {
    value: '7',
    label: '被系统过滤'
  }],
  loseReason,
  maritalStatus: [{
    value: '0',
    label: '未婚'
  }, {
    value: '1',
    label: '已婚已育'
  }, {
    value: '2',
    label: '已婚未育'
  }, {
    value: '3',
    label: '离异'
  }],
  salary: [{
    value: '0,1000',
    label: '1000元以下'
  }, {
    value: '1000,2000',
    label: '1000-2000元'
  }, {
    value: '2000,4000',
    label: '2000-4000元'
  }, {
    value: '4000,6000',
    label: '4000-6000元'
  }, {
    value: '6000,8000',
    label: '6000-8000元'
  }, {
    value: '8000,10000',
    label: '8000-10000元'
  }, {
    value: '10000,15000',
    label: '10000-15000元'
  }, {
    value: '15000,20000',
    label: '15000-20000元'
  }, {
    value: '20000,30000',
    label: '20000-30000元'
  }, {
    value: '30000,50000',
    label: '30000-50000元'
  }, {
    value: '50000,70000',
    label: '50000-70000元'
  }, {
    value: '70000,100000',
    label: '70000-100000元'
  }, {
    value: '100000,999999',
    label: '100000元以上'
  }],
  resumeHandler: [
    {
      value: '0',
      label: '新简历',
      btnType: 'primary',
      btnKey: 'initial'
    },
    {
      value: '1',
      label: '已阅读',
      btnType: 'primary',
      btnKey: 'initial'
    },
    {
      value: '2',
      label: '不合适',
      btnType: 'danger',
      btnKey: 'lose'
    },
    {
      value: '3',
      label: '通过初筛',
      btnType: 'success',
      btnKey: 'pass'
    },
    {
      value: '4',
      label: '面试',
      btnType: 'success',
      btnKey: 'interviewForm'
    },
    {
      value: '9',
      label: '反馈面试结果',
      btnType: 'primary',
      btnKey: 'feedbackForm'
    },
    {
      value: '5',
      label: '录用',
      btnType: 'success',
      btnKey: 'employForm'
    },
    {
      value: '6',
      label: '已入职',
      btnType: 'success',
      btnKey: 'success'
    },
    {
      value: '7',
      label: '被过滤',
      btnType: 'warning',
      btnKey: 'nofilter'
    },
    {
      value: '8',
      label: '未入职',
      btnType: 'warning',
      btnKey: 'absent'
    },
    {
      value: '10',
      label: '面试淘汰',
      btnType: 'danger',
      btnKey: 'fail'
    }
  ],
  resumeHandlerData: {
    '7': {
      value: '7',
      label: '被过滤',
      children: [{
        value: '0',
        label: '新简历'
      }, {
        value: '4',
        label: '通过初筛'
      }]
    },
    '0': {
      value: '0',
      label: '新简历',
      children: [{
        value: '3',
        label: '通过初筛'
      }, {
        value: '2',
        label: '不合适',
        children: loseReason
      }]
    },
    '1': {
      value: '0',
      label: '已阅读',
      children: [{
        value: '3',
        label: '通过初筛'
      }, {
        value: '2',
        label: '不合适',
        children: loseReason
      }]
    },
    '2': {
      value: '2',
      label: '不合适'
    },
    '3': {
      value: '3',
      label: '通过初筛',
      children: [{
        value: '4',
        label: '面试'
      }, {
        value: '2',
        label: '不合适',
        children: loseReason
      }]
    },
    '4': {
      value: '4',
      label: '面试',
      children: [{
        value: '9',
        label: '反馈面试结果'
      }, {
        value: '4',
        label: '再次面试'
      }]
    },
    'x': {
      value: 'x',
      label: '已面试待处理',
      children: [{
        value: '9',
        label: '反馈面试结果'
      }]
    },
    '10': {
      value: '10',
      label: '面试淘汰'
    },
    'z': {
      value: 'z',
      label: '待录用'
    },
    '9': {
      value: '9',
      label: '反馈面试结果',
      children: [{
        value: '5',
        label: '录用'
      }]
    },
    '5': {
      value: '5',
      label: '录用',
      children: [{
        value: '6',
        label: '已入职'
      },
      {
        value: '8',
        label: '未入职'
      }]
    },
    '6': {
      value: '6',
      label: '已入职'
    },
    '8': {
      value: '8',
      label: '未入职'
    }
  }
}

const mutations = {
  TOGGLE_SIDEBAR: state => {
    state.sidebar.opened = !state.sidebar.opened
    state.sidebar.withoutAnimation = false
    if (state.sidebar.opened) {
      Cookies.set('sidebarStatus', 1)
    } else {
      Cookies.set('sidebarStatus', 0)
    }
  },
  CLOSE_SIDEBAR: (state, withoutAnimation) => {
    Cookies.set('sidebarStatus', 0)
    state.sidebar.opened = false
    state.sidebar.withoutAnimation = withoutAnimation
  },
  TOGGLE_DEVICE: (state, device) => {
    state.device = device
  },
  SET_SIZE: (state, size) => {
    state.size = size
    Cookies.set('size', size)
  },
  SET_AREA: (state, data) => {
    state.areaData = data
  },
  SET_TRADE: (state, data) => {
    state.tradeData = data
  },
  SET_POSITION: (state, data) => {
    state.positionData = data
  }
}

const actions = {
  toggleSideBar({
    commit
  }) {
    commit('TOGGLE_SIDEBAR')
  },
  closeSideBar({
    commit
  }, {
    withoutAnimation
  }) {
    commit('CLOSE_SIDEBAR', withoutAnimation)
  },
  toggleDevice({
    commit
  }, device) {
    commit('TOGGLE_DEVICE', device)
  },
  setSize({
    commit
  }, size) {
    commit('SET_SIZE', size)
  },
  getArea({
    commit
  }, code) {
    return new Promise((resolve, reject) => {
      baseData({
        clz: code
      }).then(res => {
        commit('SET_AREA', res.result)
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    })
  },
  getTrade({
    commit
  }, code) {
    return new Promise((resolve, reject) => {
      baseData({
        clz: code
      }).then(res => {
        commit('SET_TRADE', res.result)
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    })
  },

  getPosition({
    commit
  }, code) {
    return new Promise((resolve, reject) => {
      baseData({
        clz: code
      }).then(res => {
        commit('SET_POSITION', res.result)
        resolve(res)
      }).catch(error => {
        reject(error)
      })
    })
  }

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
